<template>
  <div class="about">
     <!--搜索-->
        <el-row>
            <el-col :span="6"><el-input v-model="dname" size="mini" placeholder="请输入账号"></el-input></el-col>
            <el-col :span="6"><el-button type="primary" @click="search"  size="mini" icon="el-icon-search">搜索</el-button>
            <!-- &nbsp;<el-button type="primary"  size="mini" icon="el-icon-circle-plus" @click="handleAdd">添加</el-button> --></el-col>
            <el-col :span="6"><div class="grid-content bg-purple-light">&nbsp;</div></el-col>
        </el-row>
        <!--分页列表显示-->
        <el-row>
            <el-table
                    :data="tableData"
                    style="width: 100%"
                    height="400">
                <el-table-column
                        prop="username"
                        label="账号">
                </el-table-column>
                <el-table-column
                        prop="createTime"
                        label="创建记录时间">
                </el-table-column>
                <el-table-column label="积分变化类型">
                        <template slot-scope="scope">
                    {{ scope.row.changeType == 1 ? '增加':'减少'}}
                </template>
                </el-table-column>
                     <el-table-column
                        prop="changeCount"
                        label="积分改变数量">
                </el-table-column>
                     <el-table-column
                        prop="operateMan"
                        label="操作人">
                </el-table-column>
                    <el-table-column
                        prop="operateNote"
                        label="操作备注">
                </el-table-column>
                <el-table-column label="积分来源" >
                   <template slot-scope="scope">
                        <p v-if="scope.row.sourceType==0">自驾服务消费金额</p>
                        <p v-if="scope.row.sourceType==1">参与官方活动</p>
                        <p v-if="scope.row.sourceType==2">官网或个人消费</p>
                    </template>
               
                </el-table-column >
              
              

                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <!-- <el-button
                                size="mini"
                                @click="handleEdit(scope.$index, scope.row)">编辑</el-button> -->
                        <el-button
                                size="mini"
                                type="danger"
                                @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-row>
        <!--分页插件-->
        <el-row>
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[2,3,5,10,100, 200, 300, 400]"
                    :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </el-row>
        <!--添加和更新 弹框-->
        <el-row>
            <el-dialog :title="title" :visible.sync="dialogFormVisible">
                <el-form :model="form">
                  <el-form-item label="会员等级" >
                        <el-input v-model="form.name" auto-complete="off"></el-input>
                    </el-form-item>
                     <el-form-item label="成长值" >
                        <el-input v-model="form.growthPoint" auto-complete="off"></el-input>
                    </el-form-item>
                     <el-form-item label="免运费标准" >
                        <el-input v-model="form.freeFreightPoint" auto-complete="off"></el-input>
                    </el-form-item>
                     <el-form-item label="是否有评论奖励特权" >
                        <el-radio v-model="form.priviledgeComment" :label="1">是</el-radio>
                        <el-radio v-model="form.priviledgeComment" :label="0">否</el-radio>    
                    </el-form-item>
                     <el-form-item label="是否有专项活动特权" >
                        <el-radio v-model="form.priviledgePromotion" :label="1">是</el-radio>
                        <el-radio v-model="form.priviledgePromotion" :label="0">否</el-radio> 
                      </el-form-item>
                     <el-form-item label="是否有会员价格特权" >
                        <el-radio v-model="form.priviledgeMemberPrice" :label="1">是</el-radio>
                        <el-radio v-model="form.priviledgeMemberPrice" :label="0">否</el-radio> 
                    </el-form-item>
                     <el-form-item label="是否有生日优惠特权" >
                        <el-radio v-model="form.priviledgeBirthday" :label="1">是</el-radio>
                        <el-radio v-model="form.priviledgeBirthday" :label="0">否</el-radio>
                    </el-form-item>
                     <el-form-item label="等级" >
                        <el-input v-model="form.note" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="积分比率" >
                        <el-input v-model="form.ratio" auto-complete="off"></el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisible = false">取 消</el-button>
                    <el-button type="primary" @click="addOrUpdate">确 定</el-button>
                </div>
            </el-dialog>
        </el-row>
  </div>
</template>
<script>
export default {
      data() {
        return {
               tableData:[],
                currentPage:1,//当前页面，默认1
                pageSize:2,//每页显示条数
                total:100,//分页总数量，默认值随便写，初始化时赋予新值
                dname:'',//查询功能
                dialogFormVisible:false,
                title:'会员等级添加',
                form:{}
        }
      },
       created:function(){
               //初始化
                this.loadData();
            },
            methods:{
                //加载数据
                loadData(){
                   //获取数据
                          this.$http.post("/api/mbs/integrationHistory/queryAll?pageNo="+this.currentPage+"&pageSize="+this.pageSize,{
                                            username:this.dname
                                      }).then((response) => {
                                                 console.log(response);
                                              if(response.data.code==2000){
                                                  this.tableData = response.data.data.list;
                                                  this.total = response.data.data.total;
                                              }
                                })  
                        
                },
                //各种绑定事件方法
                //每页数量发生变化
                handleSizeChange(val) {
                    console.log(`每页 ${val} 条`);
                    this.pageSize=val;
                    this.loadData();
                 
                },
                //当前页发生变化
                handleCurrentChange(val) {
                    console.log(`当前页: ${val}`);
                    this.currentPage=val;
                    this.loadData();
                   
                },
                //查询方法
                search(){
                   this.loadData();
                },
                //处理添加
                handleAdd(){
                    //清空原来form
                    this.form={};
                    //更新显示名称
                    this.title="会员等级添加";
                    //对话框显示
                    this.dialogFormVisible=true;
                },
                //处理编辑（弹出汽车更新对话框）
                handleEdit(index, row) {
                    console.log(index, row);
                    //{deptNo:10,dname:'ACCOUNTING',loc:'纽约'}
                    this.form=row;
                    //更新显示名称
                    this.title="会员等级更新";
                    //对话框显示
                    this.dialogFormVisible=true;
                },

                //提交表单数据（添加或者更新）
                addOrUpdate(){
                    var  url ='/api/mbs/memberLevel/update';
                    if(this.form.id==''||this.form.id==null){
                        url="/api/mbs/memberLevel/insert"
                    }
                   var _this=this;
                    //提交方法
                    this.$http.post(url, this.form)
                        .then(function (response) {
                            console.log(response);
                            //提交成功
                            if(response.data.code==2000){
                                //关闭弹出框
                                _this.dialogFormVisible=false;
                                //提示更新成功
                                _this.$message({
                                  //  message: '恭喜你，这是一条成功消息',
                                    message: response.data.message,
                                    type: 'success'
                                });
                                //重新加载数据
                                _this.loadData();
                            }else {
                                _this.$message.error(response.data.message);
                            }
                        })
                        .catch(function (error) {
                            _this.$message.error('错了哦，这是一条错误消息');
                        });
                },
                //处理删除（ 汽车删除）
                handleDelete(index, row) {
                    console.log(index, row);
                   var _this=this;
                    //确认弹框
                    this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        //执行删除
                        this.$http.delete('/api/mbs/integrationHistory/deleteById?id='+row.id)
                            .then(function (response) {
                                //判断删除是否成功
                                 if(response.data.code==2000){
                                     //提示
                                     _this.$message({
                                         type: 'success',
                                         message: '删除成功!'
                                     });
                                     //重新加载数据
                                     _this.loadData();
                                 }else {
                                     _this.$message.error(response.data.message);
                                 }
                            })
                            .catch(function (error) {
                                //失败处理
                                console.log(error);
                                _this.$message.error('删除失败!');
                            });
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                    });


                }
            }
    }
</script>
<style>

</style>
